var order = ['red', 'yellow', 'blue', 'green', 'red'];
let text = "";
Page({
  data: {
    lastX: 0,
    lastY: 0,
    scrollLeft: 0
  },
  upper: function(e) {
    console.log(e)
  },
  lower: function(e) {
    console.log(e)
  },
  handltouchmove: function (event) {
    let currentX = event.touches[0].pageX;
    let currentY = event.touches[0].pageY;
    if ((currentX - this.data.lastX) < -1)
      text = "向左滑动" ;
    else if (((currentX - this.data.lastX) > 1))
      text = "向右滑动" ;
    else
      text = "";
    //将当前坐标进行保存以进行下一次计算
    this.data.lastX = currentX
    this.data.lastY = currentY
  },
  touchend: function(e) {
    if (text == "向左滑动"){
      if (this.data.scrollLeft < 0){
        if (this.data.scrollLeft <= -627 * 3 - 490) {
          this.data.scrollLeft += 490
        }else{
          this.data.scrollLeft += 627
        }
      }else{
        this.data.scrollLeft = 0
      }
      this.setData({
        scrollLeft: this.data.scrollLeft
      })
    } else if (text == "向右滑动"){
      if (this.data.scrollLeft <= -627 * 3){
        this.data.scrollLeft = -627 * 3 - 490
      }else{
        this.data.scrollLeft -= 627
      }
      this.setData({
        scrollLeft: this.data.scrollLeft
      })
    }
  },
  handletouchtart: function (event) {
    this.data.lastX = event.touches[0].pageX
    this.data.lastY = event.touches[0].pageY
  },
})